home *** CD-ROM | disk | FTP | other *** search
- Unit X_Table;
- {$R-,S-,O+}
-
- { The ExtendedTable provides the ExtendedArray with access to all Lobes, }
- { either directly, as in the case of a Lobe which currently resides in }
- { one of the (MaxBuff+1) array locations, or by swapping one of these to }
- { disk and swapping in the requested Lobe. }
-
- INTERFACE
-
- Uses XManager,XGlobals,ExtBuff,FlexPntr;
-
- Type
- BufferWindow = Array[0..MaxBuff] of ExtendedBuffer;
- Priority = Array[0..MaxBuff] of LongInt;
-
- ExtendedTable = Object
-
- Buff : BufferWindow;
- Pty : Priority;
- Keys : Manager;
- Ex : Ext;
-
- Procedure Create;
- Procedure Init (NumLobes : Word; LobeSize : Word);
-
- Function Retrieve (Lobe : Word) : FlexPtr;
-
- Procedure Update (Lobe : Word; Field : FlexPtr);
-
- Procedure Destroy;
- End;
-
- IMPLEMENTATION
-
- Procedure ExtendedTable.Create;
- Var
- I : Byte;
- Begin
- For I := 0 to MaxBuff do
- Begin
- Pty[I] := 0;
- Buff[I].Create
- End;
- Keys.Create;
- Ex := ''
- End;
-
- Procedure ExtendedTable.Destroy;
- Var
- I : Byte;
- J : Word;
- F : File;
- Begin
- For I := 0 to MaxBuff do
- Begin
- Pty[I] := 0;
- Buff[I].Destroy
- End;
- For J := 0 to Keys.MaxSize-1 do
- Begin
- {$I-}
- Assign (F,Keys.GetTag (J)+Ex);
- Reset (F);
- {$I+}
- If IOResult = 0 Then
- Begin
- Close (F);
- Erase (F)
- End
- End;
- Keys.Destroy;
- Ex := ''
- End;
-
- Procedure ExtendedTable.Init (NumLobes : Word; LobeSize : Word);
- Var
- I : Word;
- J : Byte;
- Begin
- Ex := Generated_Extension;
- Keys.Init (NumLobes);
- For I := 0 to NumLobes-1 do Keys.SetTag (I,'}'+Int_To_Short (I)+ '{');
-
- For J := 0 to MaxBuff do
- Begin
- Buff[J].Init (Keys.GetTag(J),Ex,LobeSize);
- Pty[J] := 1;
- Keys.Load (J,J)
- End
- End;
-
- Function LeastPty (P : Priority) : Byte;
-
- { Provide the Index of the Buffer with the least priority }
-
- Var
- I,K : Byte;
- J : LongInt;
- Begin
- J := P[0];
- K := 0;
- For I := 1 to MaxBuff do
- If P[I] < J Then
- Begin
- J := P[I];
- K := I
- End;
- LeastPty := K;
- End;
-
- Function ExtendedTable.Retrieve (Lobe : Word) : FlexPtr;
- Var
- K : Byte;
- Begin
- If Keys.InMem (Lobe) Then {If its already in memory, simply provide it}
- K := Keys.MemIndex (Lobe)
- Else
- Begin {Find InMem Lobe with Least Priority and swap it out}
- K := LeastPty (Pty); {InMem address of Lobe with Least Priority}
-
- Keys.UnLoad (Keys.ManIndex (Buff[K].Tag));
- Keys.Load (Lobe,K);
- Buff[K].SwapData (Keys.GetTag (Lobe));
-
- Pty[K] := Keys.PriIndex (K)
- End;
- Retrieve := Buff[K].Data
- End;
-
- Procedure ExtendedTable.Update (Lobe : Word; Field : FlexPtr);
- Var
- K : Byte;
- Begin
- If Keys.InMem (Lobe) Then
- K := Keys.MemIndex (Lobe)
- Else
- Begin
- K := LeastPty (Pty);
-
- Keys.UnLoad (Keys.ManIndex (Buff[K].Tag));
- Keys.Load (Lobe,K);
- Buff[K].SwapData (Keys.GetTag (Lobe));
-
- Pty[K] := Keys.PriIndex (K)
- End;
- Buff[K].Accept (Field)
- End;
-
- BEGIN
- END.